//一个非常简单的store的示例
import Vue from 'vue';
import Vuex from 'vuex';

//数据持久化插件
import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        loading:false,
		token: '',
		memID: '',
		
		app_token:'',
		phone:'',
		wx_auth:'',
		realname:{},
    },
    mutations: {
		
		getInfo(state,payload){
			if(payload.app_token) state.app_token = payload.app_token;
			if(payload.phone) state.phone = payload.phone;
			if(payload.wx_auth) state.wx_auth = payload.wx_auth;
		},
		
		getRealname(state,payload){
			if(payload) state.realname = payload;
		},
		
        //tf作为主动控制的参数
        switch_loading(state,tf){
            if(tf){
                state.loading = tf;
            }else{
                state.loading = !state.loading
            }
        },
		
    },
	
	
	plugins: [  
		    // 可以有多个持久化实例  
		    createPersistedState({  
		      key: 'store',  // 状态保存到本地的 key   
		      paths: ['app_token','phone','wx_auth','realname'],  
		      storage: {  // 存储方式定义  
		        getItem: (key) => uni.getStorageSync(key), // 获取  
		        setItem: (key, value) => uni.setStorageSync(key, value), // 存储  
		        removeItem: (key) => uni.removeStorageSync(key) // 删除  
		      }  
		    })  
		  ] 

})
export default store